﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Text.RegularExpressions;
using System.Data.SqlClient;
using AspNetCs.Config;
using AspNetCs.Bll;

#region 文章

/// <summary>
/// Article 文章的摘要说明
/// </summary>
public class Article
{
    private string TableName = "Article";
    public string _TableName { get { return TableName; } }

    public Article()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }
    public ArticleInfo GetArticle(DataRow dr)
    {
        ArticleInfo model = new ArticleInfo();
        if (dr != null)
        {



            if (dr["ArticleID"].ToString() != "") model._ArticleID = Convert.ToInt32(dr["ArticleID"]);
            if (dr["SpecialID"].ToString() != "") model._SpecialID = Convert.ToInt32(dr["SpecialID"]);
            if (dr["Title"].ToString() != "") model._Title = (dr["Title"].ToString());
            if (dr["CopyFrom"].ToString() != "") model._CopyFrom = (dr["CopyFrom"].ToString());
            if (dr["Key"].ToString() != "") model._Key = (dr["Key"].ToString());
            if (dr["Hits"].ToString() != "") model._Hits = Convert.ToInt32(dr["Hits"].ToString());
            if (dr["UpdateTime"] != null) model._UpdateTime = Convert.ToDateTime(dr["UpdateTime"].ToString());
            if (dr["isdefault"].ToString() != "") model._isdefault = Convert.ToInt32(dr["isdefault"].ToString());
            if (dr["isHot"].ToString() != "") model._isHot = Convert.ToInt32(dr["isHot"].ToString());
            if (dr["OnTop"].ToString() != "") model._OnTop = Convert.ToInt32(dr["OnTop"].ToString());
            if (dr["Elite"].ToString() != "") model._Elite = Convert.ToInt32(dr["Elite"].ToString());
            if (dr["Passed"].ToString() != "") model._Passed = Convert.ToInt32(dr["Passed"].ToString());
            if (dr["Content"].ToString() != "") model._Content = CommonClass.EncodeHtml(dr["Content"].ToString());
            if (dr["IncludePic"].ToString() != "") model._IncludePic = Convert.ToInt32(dr["IncludePic"].ToString());
            if (dr["DefaultPicUrl"].ToString() != "") model._DefaultPicUrl = CommonClass.EncodeHtml(dr["DefaultPicUrl"].ToString());
            if (dr["PaginationType"].ToString() != "") model._PaginationType = Convert.ToInt32(dr["PaginationType"].ToString());
            if (dr["ClassID"].ToString() != "") model._ClassID = Convert.ToInt32(dr["ClassID"].ToString());
            if (dr["isdel"].ToString() != "") model._isdel = Convert.ToInt32(dr["isdel"].ToString());
            if (dr["TitleFontColor"].ToString() != "") model._TitleFontColor = (dr["TitleFontColor"].ToString());
            if (dr["TitleFontType"].ToString() != "") model._TitleFontType = Convert.ToInt32(dr["isdel"].ToString());
            if (dr["MaxCharPerPage"].ToString() != "") model._MaxCharPerPage = Convert.ToInt32(dr["MaxCharPerPage"].ToString());


        }
        return model;
    }

    /// <summary>
    /// 返回Article表所有数据
    /// </summary>
    /// <returns></returns>
    public DataSet GetDs()
    {
        return this.GetWhereds("");
    }

    /// <summary>
    /// 根据where条件返回表中查询结果DataSet
    /// </summary>
    /// <param name="whereStr">where条件，必须跟"where"</param>
    /// <returns></returns>
    public DataSet GetWhereds(string whereStr)
    {
        dbclass Conn = new dbclass();
        DataSet ds = new DataSet();
        string Sqlstr = "Select * from " + TableName + " " + whereStr;
        try
        {
            ds = Conn.GetSql_DataSet(Sqlstr);
        }
        finally
        {
            Conn.close();
            Conn.Dispose();
        }
        return ds;
    }
    /// <summary>
    /// 根据ArticleId查询结果返回DataRow
    /// </summary>
    /// <param name="ArticleId">参数:ArticleId</param>
    /// <returns></returns>
    public DataRow GetWheredr(int ArticleId)
    {
        DataRow dr = null;
        DataSet ds = GetWhereds(" where isdel=0 and Passed=1 and  ArticleId=" + ArticleId);
        if (ds.Tables[0].Rows.Count > 0)
        {
            dr = ds.Tables[0].Rows[0];
        }

        return dr;
    }
    /// <summary>
    /// 根据关键字，返回相关新闻DataTable
    /// </summary>
    /// <param name="key"></param>
    /// <returns></returns>
    public static DataSet ArticleRelated(string key, string ArticleID)
    {
        HttpResponse Response = HttpContext.Current.Response;
        DataSet ds = new DataSet();
        int strLen = 0;
        string whereStr = "";
        strLen = Regex.Matches(key, ",").Count;
        if (strLen > 0)
        {
            whereStr = " and (";
            for (int i = 0; i <= strLen; i++)
            {
                if (key.Split(',')[i].ToString() != "")
                {
                    if (i > 0)
                    {
                        whereStr = whereStr + " or (Title like '%" + key.Split(',')[i].ToString() + "%' or [key] like '%" + key.Split(',')[i].ToString() + "%')";
                    }
                    else
                    {
                        whereStr = whereStr + "(Title like '%" + key.Split(',')[i].ToString() + "%' or [key] like '%" + key.Split(',')[i].ToString() + "%')";
                    }

                }

            }


            whereStr = whereStr + " )";
        }
        else
        {
            whereStr = " and(Title like '%" + key + "%' or [key] like '%" + key + "%')";
        }
        dbclass Conn = new dbclass();
        ds = Conn.GetSql_DataSet("Select * from " + new Article()._TableName + " where isdel=0 and Passed=1 and ArticleID<>" + ArticleID + " " + whereStr);
        return ds;
    }
    /// <summary>
    /// 文章查询
    /// </summary>
    /// <param name="SpecialID">专题与专访ID[0=不限制]</param>
    /// <param name="isdefault">是否焦点新闻[0=不是,1=是,2=所有]</param>
    /// <param name="ishot">是否热门[0=不是,1=是,2=所有]</param>
    /// <param name="OnTop">是否固定[0=不是,1=是,2=所有]</param>
    /// <param name="Elite">是否为精华[0=不是,1=是,2=所有]</param>
    /// <param name="Passed">是否为审核[0=不是,1=是,2=所有]</param>
    /// <param name="IncludePic">是否包含图片[0=不是,1=是,2=所有]</param>
    /// <param name="isdel">是否删除[0=未删除,1=已删除,2=所有]</param>
    /// <param name="classid">分类ID[0=所有]</param>
    /// <returns></returns>
    public static DataSet Select_Articel(int SpecialID, int isdefault, int ishot, int OnTop, int Elite, int Passed, int IncludePic, int isdel, int classid, string WhereOrder)
    {
        HttpResponse Response = HttpContext.Current.Response;//Response对象
        dbclass Conndb = new dbclass();
        DataSet ds = new DataSet();
        string WhereStr = " Where ArticleID<>0 ";
        if (SpecialID != 0) { WhereStr = WhereStr + " and SpecialID=" + SpecialID; }
        if (isdefault != 2) { WhereStr = WhereStr + " and isdefault=" + isdefault; }
        if (ishot != 2) { WhereStr = WhereStr + " and isHot=" + ishot; }
        if (OnTop != 2) { WhereStr = WhereStr + " and OnTop=" + OnTop; }
        if (Elite != 2) { WhereStr = WhereStr + " and Elite=" + Elite; }
        if (Passed != 2) { WhereStr = WhereStr + " and Passed=" + Passed; }
        if (IncludePic != 2)
        {
            if (IncludePic == 1)
            {
                WhereStr = WhereStr + " and DefaultPicUrl<>''";
            }

            WhereStr = WhereStr + " and IncludePic=" + IncludePic;

        }
        if (isdel != 2) { WhereStr = WhereStr + " and isdel=" + isdel; }

        if (classid != 0)
        {
            WhereStr = WhereStr + " and classid=" + classid;

            string childId = ArticleClass.ChildId(classid.ToString());
            if (childId != "")
            {
                WhereStr = WhereStr + "  and classid in(" + childId + ")";
            }
        }
        WhereStr = WhereStr + " " + WhereOrder;
        //Response.Write(WhereStr);

        ds = new Article().GetWhereds(WhereStr);
        return ds;
    }

    /// <summary>
    /// 文章的CSS样式
    /// </summary>
    /// <param name="colorSet">颜色</param>
    /// <param name="TitleFontType">标题字形。[0为规则，1为粗体，2为斜体，3为粗体+斜体,4为下划线,5为粗体+斜体+下划线]</param>
    /// <returns></returns>
    public static string ArticelStyle(string colorSet, int TitleFontType)
    {
        string Sqlstyle = "";

        if (colorSet != "")
        {
            Sqlstyle = Sqlstyle + "text-decoration:none;color:" + colorSet + ";";
        }

        switch (TitleFontType)
        {
            case 1:
                Sqlstyle = Sqlstyle + "font-weight:bold;";
                break;
            case 2:
                Sqlstyle = Sqlstyle + "font-style: italic; ";
                break;
            case 3:
                Sqlstyle = Sqlstyle + "font-weight:bold;font-style: italic;";
                break;
            case 4:
                Sqlstyle = Sqlstyle + "text-decoration:underline;";
                break;
            case 5:
                Sqlstyle = Sqlstyle + "text-decoration:underline;font-weight:bold;font-style: italic;";
                break;
        }
        return Sqlstyle;
    }

}
#endregion

#region 文章分类
/// <summary>
/// 文章分类的摘要说明
/// </summary>
public class ArticleClass
{
    private string TableName = "ArticleClass";
    public string _TableName { get { return TableName; } }

    public ArticleClass()
    {
        //构造函数
    }
    public ArticleClassInfo GetArticleClass(DataRow dr)
    {
        ArticleClassInfo ArtCls = new ArticleClassInfo();
        if (dr != null)
        {
            if (dr["classid"].ToString() != "") { ArtCls._Classid = Convert.ToInt32(dr["classid"].ToString()); }
            if (dr["className"].ToString() != "") { ArtCls._className = Convert.ToString(dr["className"].ToString()); }
            if (dr["parentId"].ToString() != "") { ArtCls._parentId = Convert.ToInt32(dr["parentId"].ToString()); }
            if (dr["ParentPath"].ToString() != "") { ArtCls._ParentPath = Convert.ToString(dr["ParentPath"].ToString()); }
            if (dr["Depth"].ToString() != "") { ArtCls._Depth = Convert.ToInt32(dr["Depth"].ToString()); }
            if (dr["RootID"].ToString() != "") { ArtCls._RootID = Convert.ToInt32(dr["RootID"].ToString()); }
            if (dr["Child"].ToString() != "") { ArtCls._Child = Convert.ToInt32(dr["Child"].ToString()); }
            if (dr["PrevID"].ToString() != "") { ArtCls._PrevID = Convert.ToInt32(dr["PrevID"].ToString()); }
            if (dr["NextID"].ToString() != "") { ArtCls._NextID = Convert.ToInt32(dr["NextID"].ToString()); }
            if (dr["OrderID"].ToString() != "") { ArtCls._OrderID = Convert.ToInt32(dr["OrderID"].ToString()); }
            if (dr["LinkUrl"].ToString() != "") { ArtCls._LinkUrl = Convert.ToString(dr["LinkUrl"].ToString()); }
            if (dr["ClassPicUrl"].ToString() != "") { ArtCls._ClassPicUrl = Convert.ToString(dr["ClassPicUrl"].ToString()); }
            if (dr["IsElite"].ToString() != "") { ArtCls._IsElite = Convert.ToInt32(dr["IsElite"].ToString()); }
            if (dr["Readme"].ToString() != "") { ArtCls._Readme = dr["Readme"].ToString(); }
        }
        return ArtCls;

    }
    public static ArticleClassInfo GetModel(int ClassId)
    {
        dbclass conn = new dbclass();
        DataTable Dt = conn.GetSql_DataSet("Select Top 1 * from ArticleClass Where ClassID=" + ClassId + "").Tables[0];
        return new ArticleClass().GetArticleClass(Dt.Rows[0]);
    }

    /// <summary>
    ///文章分类 返回DataSet
    /// </summary>
    /// <param name="WhereStr">where条件,后面必须跟"where"</param>
    /// <returns></returns>
    public DataSet GetArticleClass(string WhereStr)
    {
        string Sqlstr = "Select  * from " + TableName + " " + WhereStr;
        dbclass Conn = new dbclass();
        try
        {
            return Conn.GetSql_DataSet(Sqlstr);
        }
        catch
        {
            return null;
        }
        finally
        {
            Conn.close();
            Conn.Dispose();
        }
    }
    /// <summary>
    /// 文章分类 返回DataRow
    /// </summary>
    /// <param name="classid">分类所对应的ID</param>
    /// <returns></returns>
    public DataRow GetArticleClassRow(int classid)
    {
        DataSet ds = new DataSet();
        string wherestr = " where classid=" + classid;
        ds = this.GetArticleClass(wherestr);
        if (ds != null)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                return ds.Tables[0].Rows[0];
            }
            else
            {
                return null;
            }
        }
        else
        {
            return null;
        }
    }

    /// <summary>
    /// 根据parentId返回所包含的所有子类
    /// </summary>
    /// <param name="_parentId">父级ID</param>
    /// <returns></returns>
    public static string ChildId(string _parentId)
    {
        string ReId = "";
        dbclass Conn = new dbclass();
        DataSet ds = Conn.GetSql_DataSet("Select * from  " + new ArticleClass()._TableName + " where parentId=" + _parentId);
        if (ds.Tables[0].Rows.Count > 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ReId = ReId + dr["Classid"].ToString() + ",";
            }
        }
        if (ReId.Length > 0)
        {
            ReId = ReId.Substring(0, ReId.Trim().LastIndexOf(","));
        }
        return ReId;
    }
    /// <summary>
    /// 无限级分类添加
    /// </summary>
    /// <param name="model"></param>
    public static void ArticleClassAdd(ArticleClassInfo model)
    {
        HttpResponse Response = HttpContext.Current.Response;

        int MaxClassID = 0, ClassID = 1, MaxRootID = 0, RootID = 0, PrevOrderID = 0, Child = 0, PrevID = 0, ParentDepth = 0;
        string Sql = "", ParentName = "", ParentPath = "";
        bool FoundErr = false;


        object obj = null, rootobj = null;
        dbclass Conn = new dbclass();
        Sql = "Select  Max(ClassID) from ArticleClass";
        obj = Conn.GetOneFile(Sql);

        if (obj != null)
        {
            if (!obj.ToString().Equals(""))
            {
                MaxClassID = (int)obj;
            }

        }
        ClassID = MaxClassID + 1;
        Conn.close();
        Conn.Dispose();

        Sql = "Select  Max(rootid) from ArticleClass";
        dbclass Conndb = new dbclass();
        rootobj = Conndb.GetOneFile(Sql);
        if (rootobj != null)
        {
            if (!rootobj.ToString().Equals(""))
            {
                MaxRootID = (int)rootobj;
            }
        }
        RootID = MaxRootID + 1;
        Conndb.close();
        Conndb.Dispose();
        if (model._parentId > 0)
        {
            Sql = "Select Top 1 * from ArticleClass where classid=" + model._parentId;
            dbclass ConnClassId = new dbclass();
            SqlDataReader sdr = ConnClassId.GetSqlDataReader(Sql);
            if (sdr.HasRows)
            {
                while (sdr.Read())
                {
                    RootID = Convert.ToInt32(sdr["RootID"]);
                    ParentName = sdr["className"].ToString();
                    ParentDepth = Convert.ToInt32(sdr["Depth"].ToString());
                    ParentPath = sdr["ParentPath"].ToString();
                    Child = Convert.ToInt32(sdr["Child"].ToString());
                    ParentPath = ParentPath + "," + model._parentId;
                    PrevOrderID = Convert.ToInt32(sdr["OrderID"].ToString());
                    if (!sdr["LinkUrl"].ToString().Equals(""))
                    {
                        Response.Write("<Script>alert('不能指定外部栏目为所属栏目!');history.back()</script>");
                        Response.End();
                    }




                    if (Child > 0)
                    {

                        dbclass rsPrevOrderID = new dbclass();
                        PrevOrderID = Convert.ToInt32(rsPrevOrderID.GetOneFile("select Max(OrderID) From ArticleClass Where ParentID=" + model._parentId));
                        rsPrevOrderID.close();
                        dbclass trs = new dbclass();
                        object objTrs = trs.GetOneFile("Select ClassID From ArticleClass  where ParentID=" + model._parentId + " and OrderID=" + PrevOrderID);
                        if (objTrs != null)
                        {
                            PrevID = Convert.ToInt32(objTrs.ToString());

                        }
                        trs.close();
                        dbclass rsPrevOrderID1 = new dbclass();
                        object objOrderID1 = rsPrevOrderID1.GetOneFile("Select  Max(OrderID) From ArticleClass Where ParentPath like '" + ParentPath + ",%'");
                        if (objOrderID1 != null)
                        {
                            if (!objOrderID1.ToString().Equals(""))
                            {
                                if (Convert.ToInt32(objOrderID1) > PrevOrderID)
                                {
                                    PrevOrderID = Convert.ToInt32(objOrderID1);
                                }

                            }
                        }
                        rsPrevOrderID1.close();

                    }
                    else
                    {
                        PrevID = 0;
                    }
                }

                FoundErr = true;
            }
            sdr.Close();
            sdr.Dispose();
            ConnClassId.close();

            if (FoundErr == false)
            {
                Response.Write("<Script>alert('所属栏目已经被删除!');history.back()</script>");
                Response.End();
            }


            //  ReturnValue = ConnClassId.GetOneFile(Sql);
        }
        else
        {
            if (MaxRootID > 0)
            {
                dbclass Conntrs = new dbclass();
                object objMaxr = Conntrs.GetOneFile("Select  Classid  From  ArticleClass Where RootID=" + MaxRootID + " and  Depth=0");
                if (objMaxr != null)
                {
                    PrevID = Convert.ToInt32(objMaxr);
                }
                Conntrs.close();

            }
            else
            {
                PrevID = 0;

            }
            PrevOrderID = 0;
            ParentPath = "0";

        }
        dbclass ConnIsClassBool = new dbclass();
        Sql = "Select Count(Classid) from ArticleClass Where ParentID=" + model._parentId + " and ClassName='" + model._className + "'";
        int isBool = (int)ConnIsClassBool.GetOneFile(Sql);
        if (isBool > 0)
        {
            string Altmsg = "";
            if (model._parentId == 0)
            {
                Altmsg += "已经存在一级栏目:" + model._className;
            }
            else
            {
                Altmsg += "“" + ParentName + "”中已经存在子栏目“" + model._className + "”!";
            }
            Response.Write("<Script>alert('" + Altmsg + "');history.back()</script>");
            Response.End();

        }
        ConnIsClassBool.close();
        dbclass ConnInsertClass = new dbclass();
        if (model._parentId > 0)
        {
            ParentDepth = ParentDepth + 1;
        }
        else
        {
            ParentDepth = 0;
        }

        Sql = string.Format("Insert into  ArticleClass(Classid,ClassName,IsElite,RootID,ParentID,Depth,ParentPath,OrderID,Readme,ClassPicUrl,LinkUrl,PrevID,Types) values({0},'{1}',{2},{3},{4},{5},'{6}',{7},'{8}','{9}','{10}',{11},{12})", ClassID, model._className, model._IsElite, RootID, model._parentId, ParentDepth, ParentPath, PrevOrderID, model._Readme, model._ClassPicUrl, model._LinkUrl, PrevID,1);

        ConnInsertClass.Execute_Noget(Sql);
        if (PrevID > 0)
        {
            new dbclass().Execute_Noget("update ArticleClass Set NextID=" + ClassID + "  Where classid=" + PrevID);
        }
        if (model._parentId > 0)
        {
            new dbclass().Execute_Noget("update ArticleClass set child=child+1 where ClassID=" + model._parentId);

            new dbclass().Execute_Noget("update ArticleClass Set OrderID=OrderID+1  Where  rootid=" + RootID + " and OrderID>" + PrevOrderID);
            new dbclass().Execute_Noget("update ArticleClass  Set  OrderID=" + PrevOrderID + "+1 where ClassID=" + ClassID);
        }


        Response.Redirect("Newsclass.aspx");
        Response.End();

    }
    /// <summary>
    /// 文章分类
    /// </summary>
    /// <param name="model">分类实体</param>
    /// <param name="arrShowLine">长度为栏目层数+1的初始化Bool数组</param>
    /// <returns></returns>
    public static string ArticleClassName(ArticleClassInfo model,bool[] arrShowLine)
    {
        if (model._NextID > 0)
        {
            arrShowLine[model._Depth] = true;
        }
        else
        {
            arrShowLine[model._Depth] = false;
        }

        string Result = " ";
        if (model._Depth > 0)
        {
            for (int i = 1; i <= model._Depth; i++)
            {

                if (i == model._Depth)
                {
                    if (model._NextID > 0)
                    {

                        Result += "<img src='" + System_Lable.SystemGetCache.InstallDir + "images/tree_line2.gif' width='17' height='16' valign='abvmiddle'>";//tree_line1
                    }
                    else
                    {
                        Result += "<img src='" + System_Lable.SystemGetCache.InstallDir+ "images/tree_line2.gif' width='17' height='16' valign='abvmiddle'>";
                    }
                }
                else
                {


                    if (arrShowLine[i]==true)
                    {
                        Result += "<img src='" + System_Lable.SystemGetCache.InstallDir + "images/tree_line3.gif' width='17' height='16' valign='abvmiddle'>";

                    }
                    else
                    {
                        Result += "<img src='" + System_Lable.SystemGetCache.InstallDir + "images/tree_line4.gif' width='17' height='16' valign='abvmiddle'>";
                    }

                }

            }
        }
        if (model._Child > 0)
        {
            Result += "<img src='" + System_Lable.SystemGetCache.InstallDir + "images/tree_folder4.gif' width='17' height='16' valign='abvmiddle'>";
        }
        else
        {
            Result += "<img src='" + System_Lable.SystemGetCache.InstallDir + "images/tree_folder3.gif' width='17' height='16' valign='abvmiddle'>";
        }




        if (model._Depth == 0)
        {
            Result += "<b>";
        }
        Result += model._className;

        if (model._Child > 0)
        {
            Result += "（" + model._Child + "）";

        }
        if (model._Depth == 0)
        {
            Result += "</b>";
        }

        return Result;
    }
    /// <summary>
    /// 绑定ListBox控件
    /// </summary>
    /// <param name="Drop">ListBox控件对象</param>
    /// <param name="ParentID">父级ID</param>
    public static void ArticleClass_Bind_ListBox(ListBox Drop, int ParentID,DataTable dt)
    {
        Drop.Items.Add(new ListItem("无(作为一级栏目)", "0"));
        //dbclass ConnBind = new dbclass();
        //DataTable dt = ConnBind.GetSql_DataSet("Select * from ArticleClass order by RootID,OrderID").Tables[0];
        bool[] arrShowLine = new bool[dt.Rows.Count];

        foreach (DataRow dr in dt.Rows)
        {
            ArticleClassInfo model = ArticleClass.GetModel(Convert.ToInt32(dr["Classid"].ToString()));

            if (model._NextID > 0)
            {
                arrShowLine[model._Depth] = true;
            }
            else
            {
                arrShowLine[model._Depth] = false;
            }

            string Result = " ";
            if (model._Depth > 0)
            {
                for (int i = 1; i <= model._Depth; i++)
                {

                    if (i == model._Depth)
                    {
                        if (model._NextID > 0)
                        {

                            Result += "├";
                        }
                        else
                        {
                            Result += "└";
                        }
                    }
                    else
                    {


                        if (arrShowLine[i] == true)
                        {
                            Result += "│";

                        }
                        else
                        {
                            Result += "　";
                        }

                    }

                }
            }
            Result += model._className;
            ListItem Item = new ListItem();
            Item.Text = Result;
            Item.Value = model._Classid.ToString();
            Drop.Items.Add(Item);
        }
        Drop.Items.FindByValue(ParentID.ToString()).Selected = true;
    
    }

    /// <summary>
    /// 绑定DropDownList控件
    /// </summary>
    /// <param name="Drop">DropDownList控件对象</param>
    /// <param name="ParentID">父级ID</param>
    public static void ArticleClass_Bind_DropDownList(DropDownList Drop, int ParentID)
    {
        Drop.Items.Add(new ListItem("无(作为一级栏目)", "0"));
        dbclass ConnBind = new dbclass();
        DataTable dt = ConnBind.GetSql_DataSet("Select * from ArticleClass order by RootID,OrderID").Tables[0];
        bool[] arrShowLine = new bool[dt.Rows.Count];

        foreach (DataRow dr in dt.Rows)
        {
            ArticleClassInfo model = ArticleClass.GetModel(Convert.ToInt32(dr["Classid"].ToString()));

            if (model._NextID > 0)
            {
                arrShowLine[model._Depth] = true;
            }
            else
            {
                arrShowLine[model._Depth] = false;
            }

            string Result = " ";
            if (model._Depth > 0)
            {
                for (int i = 1; i <= model._Depth; i++)
                {

                    if (i == model._Depth)
                    {
                        if (model._NextID > 0)
                        {

                            Result += "├";
                        }
                        else
                        {
                            Result += "└";
                        }
                    }
                    else
                    {


                        if (arrShowLine[i] == true)
                        {
                            Result += "│";

                        }
                        else
                        {
                            Result += "　";
                        }

                    }

                }
            }
            Result += model._className;
            ListItem Item = new ListItem();
            Item.Text = Result;
            Item.Value = model._Classid.ToString();
            Drop.Items.Add(Item);
        }
        Drop.Items.FindByValue(ParentID.ToString()).Selected = true;

    }
    /// <summary>
    /// 移动文章栏目
    /// </summary>
    /// <param name="ParentId">父级ID</param>
    /// <param name="MoveOldId">移动的类别ID</param>
    public static void ArticleClass_Move_ListBox(int ParentId, int MoveOldId)
    {
       // string Sqlstr = "";
        //Sqlstr = "Select * from ";

    
    }





    /// <summary>
    /// 根据当前分类ID查询所属分类
    /// </summary>
    /// <param name="classid"></param>
    /// <returns></returns>
    public static string IncludeClass(int classid)
    {
        HttpResponse Response=HttpContext.Current.Response;
        dbclass Conn = new dbclass();
        DataTable dt = Conn.GetSql_DataTable("Select Top 1 * from ArticleClass Where  ClassID=" + classid);
        string Result = "";
        dbclass Cn = new dbclass();
        if (dt.Rows.Count > 0)
        {
            if (Convert.ToInt32(dt.Rows[0]["ParentID"].ToString()) <= 0)
            {
                Result += "无（作为一级栏目）";
            }
            else
            {
                DataTable dt1 = Cn.GetSql_DataTable("Select * From ArticleClass where ClassID in (" + dt.Rows[0]["ParentPath"] + ") order by Depth");
                foreach (DataRow dr in dt1.Rows)
                {
                    for (int i = 1; i <= Convert.ToInt32(dr["Depth"].ToString()); i++)
                    {
                        Result += "&nbsp;&nbsp;&nbsp;";
                    }
                    if (Convert.ToInt32(dr["Depth"].ToString()) > 0)
                    {
                        Result += "└";
                    }
                    Result += "&nbsp;" + dr["ClassName"] + "<br>";
                }
            }
        }
        Cn.close();
        Conn.close();
        return Result;
    
    }

}
#endregion


//#region 专题与专访
//public class GetSpecial
//{
//    private String TableName = "Special";
//    /// <summary>
//    /// 根据ISTYPE查询专题,专访 返回DataSet
//    /// </summary>
//    /// <param name="ontop">是否推荐</param>
//    /// <param name="num">查询数量</param>
//    /// <returns></returns>
//    public DataSet Select_Special(int ontop, int num, int istype)
//    {
//        dbclass Conndb = new dbclass();
//        DataSet ds = new DataSet();
//        string Sqlstr = "Select ";
//        if (num > 0)
//        {
//            Sqlstr = Sqlstr + " Top " + num;
//        }
//        Sqlstr = Sqlstr + " *  from " + TableName + " where isdel=0 and ischeck=1 and ontop=" + ontop + " and istype=" + istype + " order by OrderID ";
//        ds = Conndb.GetSql_DataSet(Sqlstr);
//        return ds;
//    }
//    /// <summary>
//    /// 查询专题,返回DataSet
//    /// </summary>
//    /// <param name="ontop"></param>
//    /// <param name="num"></param>
//    /// <returns></returns>
//    public DataSet Select_Special(int ontop, int num)
//    {
//        return Select_Special(ontop, num, 0);
//    }





//    public SpecialInfo GetSpecialList(DataRow dr)
//    {
//        SpecialInfo spc = new SpecialInfo();
//        if (dr != null)
//        {
//            if (dr["Specialid"].ToString() != "") { spc._Specialid = Convert.ToInt32(dr["Specialid"].ToString()); }
//            if (dr["OrderID"].ToString() != "") { spc._OrderID = Convert.ToInt32(dr["OrderID"].ToString()); }
//            if (dr["BrowsePurview"].ToString() != "") { spc._BrowsePurview = Convert.ToInt32(dr["BrowsePurview"].ToString()); }
//            if (dr["ontop"].ToString() != "") { spc._ontop = Convert.ToInt32(dr["ontop"].ToString()); }
//            if (dr["istype"].ToString() != "") { spc._istype = Convert.ToInt32(dr["istype"].ToString()); }
//            if (dr["isdel"].ToString() != "") { spc._isdel = Convert.ToInt32(dr["isdel"].ToString()); }
//            if (dr["ischeck"].ToString() != "") { spc._ischeck = Convert.ToInt32(dr["ischeck"].ToString()); }

//            if (dr["SpecialName"].ToString() != "") { spc._SpecialName = dr["SpecialName"].ToString(); }
//            if (dr["ReadMe"].ToString() != "") { spc._ReadMe = dr["ReadMe"].ToString(); }
//            if (dr["defaultpic"].ToString() != "") { spc._defaultpic = dr["defaultpic"].ToString(); }
//            if (dr["linkUrl"].ToString() != "") { spc._linkUrl = dr["linkUrl"].ToString(); }


//        }
//        return spc;
//    }
//    /// <summary>
//    /// 查询推荐专题
//    /// </summary>
//    /// <returns></returns>
//    public static SpecialInfo Select_TopSpecial()
//    {
//        SpecialInfo model = new SpecialInfo();
//        GetSpecial getspe = new GetSpecial();
//        if (getspe.Select_Special(1, 1).Tables[0].Rows.Count > 0)
//        {
//            model = getspe.GetSpecialList(getspe.Select_Special(1, 1).Tables[0].Rows[0]);
//        }
//        return model;
//    }
//    public static SpecialInfo Select_TopSpecial(int types)
//    {
//        SpecialInfo model = new SpecialInfo();
//        GetSpecial getspe = new GetSpecial();
//        if (getspe.Select_Special(1, 1, types).Tables[0].Rows.Count > 0)
//        {
//            model = getspe.GetSpecialList(getspe.Select_Special(1, 1, types).Tables[0].Rows[0]);
//        }
//        return model;
//    }




//}


//#endregion

